package com.sywb.chuangyebao.view;

import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.sywb.chuangyebao.R;
import com.sywb.chuangyebao.contract.TopicContract;

import org.bining.footstone.widget.PullToRefreshView;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 话题聚合页
 */
public class TopicActivity extends ActionbarActivity<TopicContract.Presenter> implements TopicContract.TopicView {

    @BindView(R.id.common_recycler)
    RecyclerView commonRecycler;
    @BindView(R.id.common_refresh)
    PullToRefreshView commonRefresh;
    @BindView(R.id.common_nodata_content)
    TextView commonNodataContent;
    @BindView(R.id.common_nodata_icon)
    ImageView commonNodataIcon;
    @BindView(R.id.common_nodata_subtitle)
    TextView commonNodataSubtitle;
    @BindView(R.id.common_nodata)
    RelativeLayout commonNodata;
    @BindView(R.id.tv_add_focus)
    TextView tvAddFocus;
    @BindView(R.id.ll_answer_me)
    LinearLayout llAnswerMe;
    @BindView(R.id.ll_answer_check)
    LinearLayout llAnswerCheck;

    private int topicId;

    @Override
    public int getLayoutId(Bundle savedInstanceState) {
        return R.layout.activity_topic;
    }

    @Override
    public void initView(Bundle savedInstanceState) {
        super.initView(savedInstanceState);
        if (savedInstanceState == null) {
            topicId = getIntent().getIntExtra("p0", 0);
        } else {
            topicId = savedInstanceState.getInt("p0");
        }
        setTitle(R.string.topic);
    }

    @Override
    public void initPresenter() {
        mPresenter.initPresenter(this);
    }

    @OnClick({R.id.ll_answer_check, R.id.tv_add_focus, R.id.ll_answer_me})
    public void onClick(View view) {
        if (!isCanClick(view)) return;
        switch (view.getId()) {
            case R.id.tv_add_focus:
                mPresenter.follow();
                break;
            case R.id.ll_answer_me:
                mPresenter.goConsult();
                break;
            case R.id.ll_answer_check:
                mPresenter.goAsk();
                break;
        }
    }

    @Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        outState.putLong("p0", topicId);
    }

    public int getPageNum() {
        return 2;
    }

    public int getProjectId() {
        return 0;
    }

    public int getNewsId() {
        return 0;
    }

    //    @Subscribe(thread = ThreadMode.MAIN_THREAD, tags = {@Tag(Constants.POST_SAVE_QUESTION)})
    //    public void afterAsked(String data) {
    //        mPresenter.pageNo = 1;
    //        mPresenter.initData();
    //    }

    //    @Override
    //    public boolean useRxBus() {
    //        return true;
    //    }

    @Override
    public PullToRefreshView getPullToRefreshView() {
        return commonRefresh;
    }

    @Override
    public RecyclerView getRecyclerView() {
        return commonRecycler;
    }

    @Override
    public void setNoData(boolean isNoData) {
        commonNodata.setVisibility(isNoData ? View.VISIBLE : View.GONE);
    }

    @Override
    public int getTopicId() {
        return topicId;
    }

    @Override
    public void setFollowView(boolean isConcern) {
        tvAddFocus.setText(isConcern ? R.string.btn_attentioned : R.string.add_focus);
    }

}
